<style>
.url-box_sys .layui-btn:focus
{
    color: #fff;
}
</style>
<div class="item-from-row">
    <div class="from-row-l">
        视频上传：
    </div>
    <div class="from-row-r">
        <a href="javascript:void(0);" onclick="addUrlSys();" class="el-button el-button--primary el-button--small">新增</a>
        <textarea name="video" id="video" cols="30" rows="10" style="display: none;"></textarea>
        <table class="layui-table">
            <thead>
            <tr>
                <th>链接地址</th>
                <th>选集名称</th>
                <th style="text-align: center;">时长(秒)</th>
                <th style="text-align: center;">操作</th>
                <th style="text-align: center;">试看</th>
            </tr>
            </thead>
            <tbody id="url-box_sys" class="url-box_sys" style="padding: 10px 0" >
                <tr id="num_upload_box_sys"  class='media_del_1586481014_1' data-num='1' style='margin-bottom: 10px;'>
                    <td class="th_server_name">
                        <input type="text" class="input-txt" id="video_url_sys_1" style="width: 310px;">
                    </td>
                    <td class="th_server_name">
                        <input type="text" class="input-txt" id="video_title_sys_1" style="width: 140px;">
                    </td>
                    <td class="th_server_name">
                        <input type="text" class="input-txt" id="video_time_sys_1" style="width: 60px;">
                    </td>
                    <input type="hidden" class="input-txt" id="video_size_sys_1" >
                    <input type="hidden" class="input-txt" id="video_mime_sys_1" >
                    <input type="hidden" class="input-txt" id="video_name_sys_1" >
                    <input type="file" class="input-txt" id="qiniu_click_sys_1" onchange="QiniuUpload(1);" style="display: none;">
                    <input type="file" class="input-txt" id="oss_click_sys_1" onchange="OssUpload(1);" style="display: none;">
                    <input type="file" class="input-txt" id="cos_click_sys_1" onchange="CosUpload(1);" style="display: none;">
                    <input type="file" class="input-txt" id="aws_click_sys_1" onchange="AwsUpload(1);" style="display: none;">
                    <td style="text-align: center;">
                        {if isset($channelRow.data.qiniuyun_open) && $channelRow.data.qiniuyun_open == 1}
                        <a href="javascript:void(0);" class="fc-colours" id="qiniu_upload_video_sys_1" onclick="click_qiniu_sys(1);">七牛云上传</a>
                        {elseif isset($channelRow.data.oss_open) && $channelRow.data.oss_open == 1}
                        <a href="javascript:void(0);" class="fc-colours" id="oss_upload_video_sys_1" onclick="click_oss_sys(1);">oss上传</a>
                        {elseif isset($channelRow.data.cos_open) && $channelRow.data.cos_open == 1}
                        <a href="javascript:void(0);" class="fc-colours" id="cos_upload_video_sys_1" onclick="click_cos_sys(1);">cos上传</a>
                        {elseif isset($channelRow.data.aws_open) && $channelRow.data.aws_open == 1}
                        <a href="javascript:void(0);" class="fc-colours" id="aws_upload_video_sys_1" onclick="click_aws_sys(1);">亚马逊S3上传</a>
                        {else/}
                        <a href="javascript:void(0);" class="fc-colours" id="upload_video_sys_1" data-num='1'>本地上传</a>
                        {/if}
                        <br><a href="javascript:void(0);" class="fc-colours" onclick="media_del('1');">删除</a>
                    </td>
                    <td style="text-align: center;">
                        <label onselectstart="return false"><input type="checkbox" id="video_gratis_sys_1" value="1"></label>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<div class="item-from-row">
    <div class="from-row-l">
        附件地址：
    </div>
    <div class="from-row-r">
        <input type="text" name="addonFieldExt[courseware]" value="" id="addonFieldExt_courseware" class="el-input__inner w500">
        <input type="file" id="courseware_file" data-type='local' onchange="upload_file_courseware_1585641738(this)" style="display: none;">
        {if isset($channelRow.data.qiniuyun_open) && $channelRow.data.qiniuyun_open == 1}
        &nbsp;<a href="javascript:void(0);" class="el-button el-button--primary is-plain el-button--small" id="upload_addonFieldExt_courseware_qiniu" onclick="$('#courseware_file').attr('data-type','qiniu').trigger('click');">七牛云上传</a>
        {elseif isset($channelRow.data.oss_open) && $channelRow.data.oss_open == 1}
        &nbsp;<a href="javascript:void(0);" class="el-button el-button--primary is-plain el-button--small" id="upload_addonFieldExt_courseware_oss" onclick="$('#courseware_file').attr('data-type','oss').trigger('click');">oss上传</a>
        {elseif isset($channelRow.data.cos_open) && $channelRow.data.cos_open == 1}
        &nbsp;<a href="javascript:void(0);" class="el-button el-button--primary is-plain el-button--small" id="upload_addonFieldExt_courseware_cos" onclick="$('#courseware_file').attr('data-type', 'cos').trigger('click');">cos上传</a>
        {elseif isset($channelRow.data.aws_open) && $channelRow.data.aws_open == 1}
        &nbsp;<a href="javascript:void(0);" class="el-button el-button--primary is-plain el-button--small" id="upload_addonFieldExt_courseware_aws" onclick="$('#courseware_file').attr('data-type', 'aws').trigger('click');">亚马逊S3上传</a>
        {else/}
        &nbsp;<a href="javascript:void(0);" class="el-button el-button--primary is-plain el-button--small" id="upload_addonFieldExt_courseware_local" onclick="$('#courseware_file').attr('data-type','local').trigger('click');">本地上传</a>
        {/if}
    </div>
</div>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例

        //创建监听函数
        var xhrOnProgress=function(fun) {
            xhrOnProgress.onprogress = fun; //绑定监听
            //使用闭包实现监听绑
            return function() {
                var xhr = $.ajaxSettings.xhr(); //通过此方法获得XMLHttpRequest对象
                //判断监听函数是否为函数
                if (typeof xhrOnProgress.onprogress !== 'function') {
                    return xhr;
                }
                //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                if (xhrOnProgress.onprogress && xhr.upload) {
                    xhr.upload.onprogress = xhrOnProgress.onprogress;
                }
                return xhr;
            }
        };

        upload.render({
            elem: "#upload_video_sys_1" //绑定元素
            ,url: "{:url('Uploadify/upVideo', ['savepath'=>'media'])}" //上传接口
            ,accept: 'video' //视频
            ,exts: '{$media_type}'
            ,size: {$upload_max_filesize} //限制文件大小，单位 KB
            ,before: function(obj){
                $("#upload_video_sys_1").text('等待中...');
            }
            ,xhr:xhrOnProgress
            ,progress: function(percent) {
                //上传进度回调 value进度值
                $("#upload_video_sys_1").text('上传中...'+percent+'%');
            }
            ,done: function(res){
                if ("SUCCESS" == res.state) {
                    $("#video_url_sys_1").val(res.url);
                    $("#video_time_sys_1").val(res.time);
                    $("#video_size_sys_1").val(res.size);
                    $("#video_mime_sys_1").val(res.mime);
                    $("#video_name_sys_1").val(res.title);
                    $("#upload_video_sys_1").text(ey_foreign_system10);
                    setTimeout(function(){
                        $('#upload_video_sys_1').text('本地上传');
                    }, 2000 )
                }else {
                    $("#upload_video_sys_1").text('上传失败');
                    setTimeout(function(){
                        $('#upload_video_sys_1').text('本地上传');
                    }, 2000 )
                    layer.msg(res.state,{icon: 2});
                }
            }
            ,error: function(){
                // layer.close(load); //关闭loading
            }
        });
    });
    function addUrlSys(){
        var is_show_qiniuyun = {$channelRow.data.qiniuyun_open|default=0};
        var is_show_oss = {$channelRow.data.oss_open|default=0};
        var is_show_cos = {$channelRow.data.cos_open|default=0};
        var is_show_aws = {$channelRow.data.aws_open|default=0};

        var num = $("#url-box_sys #num_upload_box_sys").last().attr("data-num");

        if (!num){
            num=0;
        }
        num++;
        var html = "";
        html += "<tr id=\"num_upload_box_sys\"  class='media_del_1586481014_"+num+"' data-num='"+num+"' style='margin-bottom: 10px;'>\n" +
            "                            <td class=\"th_server_name\">\n" +
            "                            <input type=\"text\" class=\"input-txt\" id=\"video_url_sys_"+num+"\" style=\"width: 310px !important;\" >\n" +
            "                            </td>\n" +
            "                            <td class=\"th_server_name\">\n" +
            "                            <input type=\"text\" class=\"input-txt\" id=\"video_title_sys_"+num+"\" style=\"width: 140px !important;\">\n" +
            "                            </td>\n" +
            "                            <td class=\"th_server_name\">\n" +
            "                            <input type=\"text\" class=\"input-txt\" id=\"video_time_sys_"+num+"\" style=\"width: 60px !important;\">\n" +
            "                            </td>\n" +
            "                            <input type=\"hidden\" class=\"input-txt\" id=\"video_size_sys_"+num+"\">" +
            "                            <input type=\"hidden\" class=\"input-txt\" id=\"video_mime_sys_"+num+"\">" +
            "                            <input type=\"hidden\" class=\"input-txt\" id=\"video_name_sys_"+num+"\">" +
            "                            <input type=\"file\" class=\"input-txt\" id=\"qiniu_click_sys_"+num+"\" onchange=\"QiniuUpload('"+num+"');\" style=\"display: none;\">\n"+
            "                            <input type=\"file\" class=\"input-txt\" id=\"oss_click_sys_"+num+"\" onchange=\"OssUpload('"+num+"');\" style=\"display: none;\">\n"+
            "                            <input type=\"file\" class=\"input-txt\" id=\"cos_click_sys_"+num+"\" onchange=\"CosUpload('"+num+"');\" style=\"display: none;\">\n"+
            "                            <input type=\"file\" class=\"input-txt\" id=\"aws_click_sys_"+num+"\" onchange=\"AwsUpload('"+num+"');\" style=\"display: none;\">\n"+
            "                            <td style=\"text-align: center;\">\n";
        if (is_show_qiniuyun == 1) {
            html += "                     <a href=\"javascript:void(0);\" class=\"fc-colours\" id=\"qiniu_upload_video_sys_"+num+"\" onclick=\"click_qiniu_sys('"+num+"');\">七牛云上传</a>\n";
        }else if (is_show_oss == 1) {
            html += "                     <a href=\"javascript:void(0);\" class=\"fc-colours\" id=\"oss_upload_video_sys_"+num+"\" onclick=\"click_oss_sys('"+num+"');\">oss上传</a>\n";
        }else if (is_show_cos == 1) {
            html += "                     <a href=\"javascript:void(0);\" class=\"fc-colours\" id=\"cos_upload_video_sys_"+num+"\" onclick=\"click_cos_sys('"+num+"');\">cos上传</a>\n";
        }else if (is_show_aws == 1) {
            html += "                     <a href=\"javascript:void(0);\" class=\"fc-colours\" id=\"aws_upload_video_sys_"+num+"\" onclick=\"click_aws_sys('"+num+"');\">亚马逊S3上传</a>\n";
        }else{
            html += "                      <a href=\"javascript:void(0);\" class=\"fc-colours\" id=\"upload_video_sys_"+num+"\" data-num='"+num+"'>本地上传</a>\n" ;
        }
        html += "                          <br><a href=\"javascript:void(0);\" class=\"fc-colours\" onclick=\"media_del('"+num+"');\">删除</a>\n" +
            "                            </td>\n" +
            "                            <td style=\"text-align: center;\">\n" +
            "          <label onselectstart='return false'><input type='checkbox' id='video_gratis_sys_"+num+"' value='1'></label>" +
            "                            </td>\n" +
            "                        </tr>";

        $('#url-box_sys').append(html);


        layui.use('upload', function(){
            var upload = layui.upload;
            //执行实例

            //创建监听函数
            var xhrOnProgress=function(fun) {
                xhrOnProgress.onprogress = fun; //绑定监听
                //使用闭包实现监听绑
                return function() {
                    var xhr = $.ajaxSettings.xhr(); //通过此方法获得XMLHttpRequest对象
                    //判断监听函数是否为函数
                    if (typeof xhrOnProgress.onprogress !== 'function') {
                        return xhr;
                    }
                    //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                    if (xhrOnProgress.onprogress && xhr.upload) {
                        xhr.upload.onprogress = xhrOnProgress.onprogress;
                    }
                    return xhr;
                }
            };

            upload.render({
                elem: "#upload_video_sys_"+num //绑定元素
                ,url: "{:url('Uploadify/upVideo', ['savepath'=>'media'])}" //上传接口
                ,accept: 'video' //视频
                ,exts: '{$media_type}'
                ,size: {$upload_max_filesize} //限制文件大小，单位 KB
                ,before: function(obj){
                    $("#upload_video_sys_"+num).text('等待中...');
                }
                ,xhr:xhrOnProgress
                ,progress: function(percent) {
                    //上传进度回调 value进度值
                    $("#upload_video_sys_"+num).text('上传中...'+percent+'%');
                }
                ,done: function(res){
                    if ("SUCCESS" == res.state) {
                        var n = $(this.item).attr('data-num');
                        $("#video_url_sys_"+n).val(res.url);
                        $("#video_time_sys_"+n).val(res.time);
                        $("#video_size_sys_"+n).val(res.size);
                        $("#video_mime_sys_"+n).val(res.mime);
                        $("#video_name_sys_"+n).val(res.title);
                        $("#upload_video_sys_"+num).text(ey_foreign_system10);
                        setTimeout(function(){
                            $('#upload_video_sys_'+num).text('本地上传');
                        }, 2000 )
                    }else {
                        $("#upload_video_sys_"+num).text('上传失败');
                        setTimeout(function(){
                            $('#upload_video_sys_'+num).text('本地上传');
                        }, 2000 )
                        layer.msg(res.state,{icon: 2});
                    }
                }
                ,error: function(){
                    // layer.close(load); //关闭loading
                }
            });
        });
    }
    // 课件地址上传
    function upload_file_courseware_1585641738(e){
        var data_type = $(e).attr('data-type');
        if ('qiniu' == data_type) {
            upload_addonFieldExt_courseware_qiniu(e); // 七牛云上传
        } else if ('oss' == data_type) {
            upload_addonFieldExt_courseware_oss(e); // OSS上传
        } else if ('cos' == data_type) {
            upload_addonFieldExt_courseware_cos(e); // COS上传
        } else {
            var file = $(e)[0].files[0];
            if (!file) {
                return false;
            }
            var formData = new FormData();
            formData.append('file',file);
            $.ajax({
                type: 'post',
                url: "{:url('Uploadify/DownloadUploadFileAjax')}",
                data: formData,
                contentType: false,
                processData: false,
                dataType: 'json',
                xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
                    myXhr = $.ajaxSettings.xhr();
                    if (myXhr.upload) { //检查upload属性是否存在
                        //绑定progress事件的回调函数
                        // myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
                        myXhr.upload.addEventListener('progress', function(e){
                            var curr = e.loaded;
                            var total = e.total;
                            process = parseInt(curr / total * 100);
                            $("#upload_addonFieldExt_courseware_local").html('上传中...'+process+"%");
                        });
                    }

                    return myXhr; //xhr对象返回给jQuery使用
                },
                success: function (res) {
                    if (res.code==0){
                        showErrorMsg(res.msg);
                        $('#upload_addonFieldExt_courseware_local').html('本地上传');
                    }if (res.state && !res.url) {
                        showErrorMsg(res.state);
                        $('#upload_addonFieldExt_courseware_local').html('本地上传');
                    }else {
                        $("#upload_addonFieldExt_courseware_local").html(ey_foreign_system10);
                        setTimeout(function(){
                            $('#upload_addonFieldExt_courseware_local').html('本地上传');
                        }, 2000 );
                        var ori_url = $('#addonFieldExt_courseware').val();
                        $("#addonFieldExt_courseware").val(res.url);
                        //删除上次的文件
                        if (ori_url) {
                            del_media_file(ori_url)
                        }
                    }
                }
            })
        }
    }

    function upload_addonFieldExt_courseware_qiniu(obj)
    {
        var file = $("#courseware_file")[0].files[0];  //获取文件路径名
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt,1);
        if (ext==-1) {
            showErrorMsg('不支持选中的文件格式,可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('文件大小超过限制,可在附件设置中修改');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '__ROOT_DIR__/index.php?m=plugins&c=Qiniuyun&a=qiniu_upload',
            data: {_ajax:1},
            dataType: "JSON",
            success: function(res1){
                if (1 == res1.code){
                    var token  = res1.data.token;
                    var formData = new FormData();
                    formData.append('file', file);
                    formData.append('token', token);

                    fileName = res1.data.filePath + fileExt;
                    formData.append('key', fileName);
                    $.ajax({
                        url: res1.data.uphost,
                        type: 'POST',
                        dataType: 'JSON',
                        data: formData,
                        timeout: 1200000,
                        cache: false,  //默认是true，但是一般不做缓存
                        processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                        contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                        xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
                            myXhr = $.ajaxSettings.xhr();
                            if (myXhr.upload) { //检查upload属性是否存在
                                //绑定progress事件的回调函数
                                // myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
                                myXhr.upload.addEventListener('progress', function(e){
                                    var curr = e.loaded;
                                    var total = e.total;
                                    process = parseInt(curr / total * 100);
                                    $("#upload_addonFieldExt_courseware_qiniu").html('上传中...'+process+"%");
                                });
                            }

                            return myXhr; //xhr对象返回给jQuery使用
                        },
                        success: function(res2){
                            $("#upload_addonFieldExt_courseware_qiniu").html(ey_foreign_system10);
                            setTimeout(function(){
                                $('#upload_addonFieldExt_courseware_qiniu').html('七牛云上传');
                            }, 2000 );
                            var video_url = res1.data.domain+"/"+res2.key;
                            $("#addonFieldExt_courseware").val(video_url);
                        },
                        error: function(e){
                            showErrorMsg(e.responseText);
                            return false;
                        }
                    });
                }else{
                    $("#courseware_file").val('');
                    showErrorMsg(res1.msg);
                }
            },
            error: function(e){
                $("#courseware_file").val('');
                showErrorMsg(e.responseText);
            }
        });
    }
    function upload_addonFieldExt_courseware_oss(obj)
    {
        var file = $("#courseware_file")[0].files[0];  //获取文件路径名
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt,1);
        if (ext==-1) {
            showErrorMsg('不支持选中的文件格式,可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('文件大小超过限制,可在附件设置中修改');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '__ROOT_DIR__/index.php?m=plugins&c=AliyunOss&a=oss_upload',
            data: {_ajax:1},
            dataType: "JSON",
            success: function(res1){
                if (1 == res1.code){
                    fileName = res1.data.filePath + fileExt;

                    //组装发送数据
                    var request = new FormData();
                    request.append("OSSAccessKeyId",res1.data.accessid);//Bucket 拥有者的Access Key Id。
                    request.append("policy",res1.data.policy);//policy规定了请求的表单域的合法性
                    request.append("Signature",res1.data.signature);//根据Access Key Secret和policy计算的签名信息，OSS验证该签名信息从而验证该Post请求的合法性

                    request.append("key",fileName);//文件名字，可设置路径
                    request.append("success_action_status",201);// 让服务端返回200,不然，默认会返回204
                    request.append('file', file);//需要上传的文件 file

                    $.ajax({
                        url : res1.data.host,  //上传阿里地址
                        data : request,
                        processData: false,
                        cache: false,
                        contentType: false,
                        dataType: 'xml',
                        type : 'post',
                        xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
                            myXhr = $.ajaxSettings.xhr();
                            if (myXhr.upload) { //检查upload属性是否存在
                                //绑定progress事件的回调函数
                                myXhr.upload.addEventListener('progress', function(e){
                                    var curr = e.loaded;
                                    var total = e.total;
                                    var process = parseInt(curr / total * 100);
                                    $("#upload_addonFieldExt_courseware_oss").html('上传中...'+process+"%");
                                });
                            }
                            return myXhr; //xhr对象返回给jQuery使用
                        },
                        success: function(res2){
                            var res = $(res2).find('PostResponse');
                            if (res) {
                                var key =  res.find('Key').text();
                                $("#upload_addonFieldExt_courseware_oss").html(ey_foreign_system10);
                                setTimeout(function(){
                                    $('#upload_addonFieldExt_courseware_oss').html('oss上传');
                                }, 2000 );
                                var video_url = res1.data.domain+"/"+key;
                                $("#addonFieldExt_courseware").val(video_url);
                            }else{
                                $("#upload_addonFieldExt_courseware_oss").html('上传失败');
                                setTimeout(function(){
                                    $('#upload_addonFieldExt_courseware_oss').html('oss上传');
                                }, 2000 );
                            }
                        },
                        error: function(e){
                            showErrorMsg(e.responseText);
                            return false;
                        }
                    });
                }else{
                    $("#courseware_file").val('');
                    showErrorMsg(res1.msg);
                }
            },
            error: function(e){
                $("#courseware_file").val('');
                showErrorMsg(e.responseText);
            }
        });
    }
    function click_qiniu_sys(num)
    {
        $("#qiniu_click_sys_"+num).trigger("click");
    }

    function QiniuUpload(num)
    {
        var file = $("#qiniu_click_sys_"+num)[0].files[0];  //获取文件路径名
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt);
        if (ext==-1) {
            showErrorMsg('不支持选中的视频格式,可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('视频大小超过限制,可在附件设置中修改');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '__ROOT_DIR__/index.php?m=plugins&c=Qiniuyun&a=qiniu_upload',
            data: {_ajax:1},
            dataType: "JSON",
            success: function(res1){
                if (1 == res1.code){
                    var token  = res1.data.token;
                    var formData = new FormData();
                    formData.append('file', file);
                    formData.append('token', token);

                    fileName = res1.data.filePath + fileExt;
                    formData.append('key', fileName);
                    $.ajax({
                        url: res1.data.uphost,
                        type: 'POST',
                        dataType: 'JSON',
                        data: formData,
                        timeout: 1200000,
                        cache: false,  //默认是true，但是一般不做缓存
                        processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                        contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                        xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
                            myXhr = $.ajaxSettings.xhr();
                            if (myXhr.upload) { //检查upload属性是否存在
                                //绑定progress事件的回调函数
                                // myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
                                myXhr.upload.addEventListener('progress', function(e){
                                    var curr = e.loaded;
                                    var total = e.total;
                                    process = parseInt(curr / total * 100);
                                    $("#qiniu_upload_video_sys_"+num).text('上传中...'+process+"%");
                                });
                            }

                            return myXhr; //xhr对象返回给jQuery使用
                        },
                        success: function(res2){
                            $("#qiniu_upload_video_sys_"+num).text(ey_foreign_system10);
                            setTimeout(function(){
                                $('#qiniu_upload_video_sys_'+num).text('七牛云上传');
                            }, 2000 )
                            var video_url = res1.data.domain+"/"+res2.key;
                            $("#video_url_sys_"+num).val(video_url);
                            $("#video_mime_sys_"+num).val('');
                            $("#video_name_sys_"+num).val(res2.key);

                            var rx=/^https?:\/\//i;
                            if (!rx.test(video_url)) {
                                video_url = 'http:'+video_url;
                            }
                            $.ajax({
                                type: 'GET',
                                url: video_url+"?avinfo",
                                data: {},
                                dataType: "JSON",
                                success: function (res3) {
                                    $("#video_time_sys_"+num).val(parseInt(res3.format.duration));
                                    $("#video_size_sys_"+num).val(res3.format.size);
                                }
                            })
                        },
                        error: function(e){
                            showErrorMsg(e.responseText);
                            return false;
                        }
                    });
                }else{
                    $("#qiniu_click_sys_"+num).val('');
                    showErrorMsg(res1.msg);
                    return false;
                }
            },
            error: function(e){
                $("#qiniu_click_sys_"+num).val('');
                showErrorMsg(e.responseText);
                return false;
            }
        });
    }
    function click_oss_sys(num)
    {
        $("#oss_click_sys_"+num).trigger("click");
    }
    function OssUpload(num)
    {
        var file = $("#oss_click_sys_"+num)[0].files[0];  //获取文件路径名
        //获取视频时长start
        var url = URL.createObjectURL(file);
        var oVideo = document.createElement('video');
        var duration = 0;
        oVideo.setAttribute('src',url);
        oVideo.oncanplay = ()=>{
            duration = parseInt(oVideo.duration);
        }
        //获取视频时长end
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt);
        if (ext==-1) {
            showErrorMsg('不支持选中的视频格式,可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('视频大小超过限制,可在附件设置中修改');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '__ROOT_DIR__/index.php?m=plugins&c=AliyunOss&a=oss_upload',
            data: {_ajax: 1},
            dataType: "JSON",
            success: function(res1){
                if (1 == res1.code){
                    fileName = res1.data.filePath + fileExt;
                    //组装发送数据
                    var request = new FormData();
                    request.append("OSSAccessKeyId",res1.data.accessid);//Bucket 拥有者的Access Key Id。
                    request.append("policy",res1.data.policy);//policy规定了请求的表单域的合法性
                    request.append("Signature",res1.data.signature);//根据Access Key Secret和policy计算的签名信息，OSS验证该签名信息从而验证该Post请求的合法性

                    request.append("key",fileName);//文件名字，可设置路径
                    request.append("success_action_status",201);// 让服务端返回200,不然，默认会返回204
                    request.append('file', file);//需要上传的文件 file
                    $.ajax({
                        url : res1.data.host,  //上传阿里地址
                        data : request,
                        processData: false,
                        cache: false,
                        contentType: false,
                        dataType: 'xml',
                        type : 'post',
                        xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
                            myXhr = $.ajaxSettings.xhr();
                            if (myXhr.upload) { //检查upload属性是否存在
                                //绑定progress事件的回调函数
                                myXhr.upload.addEventListener('progress', function(e){
                                    var curr = e.loaded;
                                    var total = e.total;
                                    var process = parseInt(curr / total * 100);
                                    $("#oss_upload_video_sys_"+num).text('上传中...'+process+"%");
                                });
                            }
                            return myXhr; //xhr对象返回给jQuery使用
                        },
                        success : function(data) {
                            var res = $(data).find('PostResponse');
                            if (res) {
                                var key =  res.find('Key').text();
                                $("#oss_upload_video_sys_"+num).text(ey_foreign_system10);
                                setTimeout(function(){
                                    $('#oss_upload_video_sys_'+num).text('oss上传');
                                }, 2000 )
                                var video_url = res1.data.domain+"/"+key;
                                $("#video_url_sys_"+num).val(video_url);
                                $("#video_mime_sys_"+num).val('');
                                $("#video_name_sys_"+num).val(key);
                                $("#video_time_sys_"+num).val(duration);
                                $("#video_size_sys_"+num).val(file.size);
                            }else{
                                $("#oss_upload_video_sys_"+num).text('上传失败');
                                setTimeout(function(){
                                    $('#oss_upload_video_sys_'+num).text('oss上传');
                                }, 2000 )
                            }
                        },
                        error : function(e) {
                            console.log(e.responseText);
                        }
                    });
                }else{
                    $("#oss_click_sys_"+num).val('');
                    showErrorMsg(res1.msg);
                }
            },
            error: function(e){
                $("#oss_click_sys_"+num).val('');
                showErrorMsg(e.responseText);
            }
        });
    }
    /*腾讯云COS上传代码 --- 陈风任 --- 2021-02-03*/
    function click_cos_sys(num) {
        $("#cos_click_sys_"+num).trigger("click");
    }
    // 上传视频
    function CosUpload(num) {
        // 获取文件路径名
        var file = $("#cos_click_sys_"+num)[0].files[0];

        // 获取视频时长start
        var url = URL.createObjectURL(file);
        var oVideo = document.createElement('video');
        var duration = 0;
        oVideo.setAttribute('src', url);
        oVideo.oncanplay = ()=>{
            duration = parseInt(oVideo.duration);
        }
        // 获取视频时长end

        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt);
        if (ext == -1) {
            showErrorMsg('不支持选中的视频格式，可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('视频大小超过限制，可在附件设置中修改');
            return false;
        }
        var formData = new FormData();
        formData.append('file', file);
        formData.append('file_ext', fileExt);
        $.ajax({
            type: 'post',
            url: '__ROOT_DIR__/index.php?m=plugins&c=Cos&a=cos_upload&_ajax=1',
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            xhr: function () {
                myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', function(e){
                        var curr = e.loaded;
                        var total = e.total;
                        process = parseInt(curr / total * 100);
                        if (100 == process) {
                            process = 99;
                            layer_loading('上传腾讯云');
                        }
                        $("#cos_upload_video_sys_"+num).text('上传中...'+process+"%");

                    });
                }
                return myXhr;
            },
            success: function(res) {
                layer.closeAll();
                if (1 == res.code) {
                    $("#video_url_sys_" + num).val(res.data.url);
                    $("#video_title_sys_" + num).val(res.data.name);
                    $("#video_time_sys_" + num).val(duration);
                    $("#video_size_sys_" + num).val(res.data.size);
                    $("#cos_upload_video_sys_"+num).text(ey_foreign_system10);
                } else {
                    $("#cos_upload_video_sys_"+num).text('上传失败');
                }
                setTimeout(function(){
                    $('#cos_upload_video_sys_'+num).text('cos上传');
                }, 2000);
            },
            error: function(e){
                layer.closeAll();
                $("#cos_click_sys_"+num).val('');
                showErrorMsg(e.responseText);
            }
        });
    }
    /*亚马逊S3上传代码 --- 开发者*/
    function click_aws_sys(num) {
        $("#aws_click_sys_"+num).trigger("click");
    }
    // 上传视频
    function AwsUpload(num) {
        // 获取文件路径名
        var file = $("#aws_click_sys_"+num)[0].files[0];

        // 获取视频时长start
        var url = URL.createObjectURL(file);
        var oVideo = document.createElement('video');
        var duration = 0;
        oVideo.setAttribute('src', url);
        oVideo.oncanplay = ()=>{
            duration = parseInt(oVideo.duration);
        }
        // 获取视频时长end

        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExtMedia(fileExt);
        if (ext == -1) {
            showErrorMsg('不支持选中的视频格式，可在附件设置中修改');
            return false;
        }
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('视频大小超过限制，可在附件设置中修改');
            return false;
        }
        var formData = new FormData();
        formData.append('file', file);
        formData.append('file_ext', fileExt);
        $.ajax({
            type: 'post',
            url: '__ROOT_DIR__/index.php?m=plugins&c=Aws&a=aws_upload&_ajax=1',
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            xhr: function () {
                myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', function(e){
                        var curr = e.loaded;
                        var total = e.total;
                        process = parseInt(curr / total * 100);
                        if (100 == process) {
                            process = 99;
                            layer_loading('上传亚马逊S3');
                        }
                        $("#aws_upload_video_sys_"+num).text('上传中...'+process+"%");

                    });
                }
                return myXhr;
            },
            success: function(res) {
                layer.closeAll();
                if (1 == res.code) {
                    $("#video_url_sys_" + num).val(res.data.url);
                    $("#video_title_sys_" + num).val(res.data.name);
                    $("#video_time_sys_" + num).val(duration);
                    $("#video_size_sys_" + num).val(res.data.size);
                    $("#aws_upload_video_sys_"+num).text(ey_foreign_system10);
                } else {
                    $("#aws_upload_video_sys_"+num).text('上传失败');
                }
                setTimeout(function(){
                    $('#aws_upload_video_sys_'+num).text('aws上传');
                }, 2000);
            },
            error: function(e){
                layer.closeAll();
                $("#aws_click_sys_"+num).val('');
                showErrorMsg(e.responseText);
            }
        });
    }
    /* 批量导入视频信息 end */
    function urlToStr() {
        var video = [];
        $("#url-box_sys tr").each(function(){
            var n = $(this).attr('data-num');
            var arr ={};
            arr.file_url = $("#video_url_sys_"+n).val();
            if (!arr.file_url) {
                return true
            }
            arr.file_title = $("#video_title_sys_"+n).val();
            arr.file_name = $("#video_name_sys_"+n).val();
            arr.file_time = $("#video_time_sys_"+n).val();
            arr.file_size = $("#video_size_sys_"+n).val();
            arr.file_mime = $("#video_mime_sys_"+n).val();
            var gratis_checked = $("#video_gratis_sys_"+n).is(':checked');
            if (gratis_checked == true){
                arr.gratis = 1;
            } else{
                arr.gratis = 0;
            }
            video.push(arr);
        });
        video = JSON.stringify(video)
        $("#video").val(video)
    }
    //获取文件类型
    function judgeExtMedia(ext,i) {
        var type = '';
        if (i==1){
            type = "{$file_type}";
        }else{
            type = "{$media_type}";
        }
        var extArr = [];
        extArr = type.split("|");
        var ext = ext.replace(".","");

        return extArr.indexOf(ext);
    }
    //删除
    function media_del(num) {
        var media_url = $("#video_url_sys_"+num).val();
        if (media_url) {
            del_media_file(media_url);
        }
        $(".media_del_1586481014_"+num).remove();
    }
    function del_media_file(path){
        var url = '';
        {if isset($channelRow.data.qiniuyun_open) && $channelRow.data.qiniuyun_open == 1}
        url = "{:url('plugins/Qiniuyun/deleteQny')}";
        {elseif isset($channelRow.data.oss_open) && $channelRow.data.oss_open == 1}
        url = "{:url('plugins/AliyunOss/deleteOss')}";
        {elseif isset($channelRow.data.cos_open) && $channelRow.data.cos_open == 1}
        url = "{:url('plugins/Cos/deleteCos')}";
        {elseif isset($channelRow.data.aws_open) && $channelRow.data.aws_open == 1}
        url = "{:url('plugins/Aws/deleteAws')}";
        {else/}
        url = "{:url('user/Uploadify/del_local')}";
        {/if}
        $.ajax({
            type: 'GET',
            url: url,
            data: {_ajax: 1, filenames: path},
            success: function (res1) {
            }
        });
    }

</script>